/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.order.entity.serviceorder;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.jeesite.common.collect.ListUtils;
import com.jeesite.common.entity.DataEntity;
import com.jeesite.common.mybatis.annotation.Column;
import com.jeesite.common.mybatis.annotation.JoinTable;
import com.jeesite.common.mybatis.annotation.JoinTable.Type;
import com.jeesite.common.mybatis.annotation.Table;
import com.jeesite.common.mybatis.mapper.query.QueryType;
import com.jeesite.modules.base.entity.customer.Customer;
import com.jeesite.modules.base.entity.supplier.Supplier;
import com.jeesite.modules.financial.entity.lettercredit.LetterCredit;
import com.jeesite.modules.sys.entity.Company;
import org.hibernate.validator.constraints.Length;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.util.Date;
import java.util.List;

/**
 * 服务订单Entity
 * @author Kilo
 * @version 2021-03-05
 */
@Table(name="t_service_order", alias="a", columns={
		@Column(name="service_order_id", attrName="serviceOrderId", label="服务订单ID", isPK=true),
		@Column(name="service_order_code", attrName="serviceOrderCode", label="编号"),
		@Column(name="investor_id", attrName="investorId", label="国内资方"),
		@Column(name="company_id", attrName="company.companyCode", label="代理公司"),
		@Column(name="year_car_sale_purchase_agreement_id", attrName="yearCarSalePurchaseAgreementId", label="年度汽车买卖协议"),
//		@Column(name="customer_id", attrName="customer.customerId", label="客户"),
		@Column(name="customer_id", attrName="customerId", label="客户"),
		@Column(name="contract_number", attrName="contractNumber", label="汽车买卖合同号"),
		@Column(name="supply_chain_service_agreement_id", attrName="supplyChainServiceAgreementId", label="供应链服务协议"),
		@Column(name="foreign_businessmen_id", attrName="foreignBusinessmenId", label="外商"),
		@Column(name="purchase_commission_number", attrName="purchaseCommissionNumber", label="采购委托书号"),
		@Column(name="supplier_id", attrName="supplierId", label="供货外商"),
		@Column(name="foreign_trade_contract_number", attrName="foreignTradeContractNumber", label="外贸合同号"),
		@Column(name="payment_method", attrName="paymentMethod", label="付款方式"),
		@Column(name="date", attrName="date", label="订单日期"),
		@Column(name="order_status", attrName="orderStatus", label="状态"),
		@Column(includeEntity=DataEntity.class),
		@Column(name="latest_shipment_date", attrName="latestShipmentDate", label="最晚装船日期"),
		@Column(name="from_port", attrName="fromPort", label="装运港"),
		@Column(name="to_port", attrName="toPort", label="目的港"),
		@Column(name="trade_term", attrName="tradeTerm", label="贸易术语"),
		@Column(name="currency", attrName="currency", label="币种"),
		@Column(name="investor_profit", attrName="investorProfit", label="资方利润", comment="资方利润（元）"),
		@Column(name="lot_number", attrName="lotNumber", label="批单号"),
		@Column(name="margin_expense_ratio_id", attrName="marginExpenseRatioId", label="保证金、费用比例"),
		@Column(name="margin_ratio", attrName="marginRatio", label="保证金比例"),
		@Column(name="negotiated_ratio_id", attrName="negotiatedRatioId", label="押汇比例"),
		@Column(name="pre_pay_ratio", attrName="prePayRatio", label="预收费比例"),
		@Column(name="tentative_exchange_rate", attrName="tentativeExchangeRate", label="暂定汇率"),
		@Column(name="version", attrName="version", label="版本号"),
		@Column(name="letter_credit_code", attrName="letterCreditCode", label="信用证", isQuery=false),
		@Column(name="bzj_yus_id", attrName="bzjYusId", label="保证金预收ID"),
		@Column(name="bzj_yuf_id", attrName="bzjYufId", label="保证金预付ID"),
		@Column(name="ysfy_id", attrName="ysfyId", label="预收费用ID"),
		@Column(name="dlf_yus_id", attrName="dlfYusId", label="代理费预收ID"),
		@Column(name="dlf_yuf_id", attrName="dlfYufId", label="代理费预付ID"),
		@Column(name="dlf_yif_id", attrName="dlfYifId", label="代理费应付ID"),
		@Column(name="dlf_yis_id", attrName="dlfYisId", label="代理费应收ID"),
		@Column(name="approve_status", attrName="approveStatus", label="审批状态"),
	}, joinTable={
		@JoinTable(type=Type.LEFT_JOIN, entity= Company.class, attrName="company", alias="b",
				on="b.company_code = a.company_id", columns={
				@Column(name="company_code", label="公司编码", isPK=true),
				@Column(name="company_name", label="公司名称", isQuery=false),
		}),
		@JoinTable(type=Type.LEFT_JOIN, entity= Customer.class, attrName="customer", alias="c",
				on="c.customer_id = a.customer_id", columns={
				@Column(name="customer_id", label="客户编码", isPK=true),
				@Column(name="customer_name", label="客户名称", isQuery=false),
		}),
		@JoinTable(type=Type.LEFT_JOIN, entity= Supplier.class, attrName="supplier", alias="d",
				on="d.supplier_id = a.supplier_id", columns={
				@Column(name="supplier_id", label="供货外商编码", isPK=true),
				@Column(name="supplier_name", label="供货外商名称", isQuery=false),
		}),
		@JoinTable(type=Type.LEFT_JOIN, entity= Supplier.class, attrName="investor", alias="e",
				on="e.supplier_id = a.investor_id", columns={
				@Column(name="supplier_id", label="国内资方编码", isPK=true),
				@Column(name="supplier_name", label="国内资方名称", isQuery=false),
		}),
		@JoinTable(type=Type.LEFT_JOIN, entity= Supplier.class, attrName="foreignBusinessmen", alias="f",
				on="f.supplier_id = a.foreign_businessmen_id", columns={
				@Column(name="supplier_id", label="外商编码", isPK=true),
				@Column(name="supplier_name", label="外商名称", isQuery=false),
		}),
		@JoinTable(type = JoinTable.Type.LEFT_JOIN, entity = LetterCredit.class, attrName = "letterCredit", alias = "g",
				on = "g.letter_credit_id = a.letter_credit_code",
				columns = {
				@Column(name = "letter_credit_id", label = "信用证ID", isPK = true),
				@Column(name = "letter_credit_code", label = "信用证编号"),
		}),
	},orderBy="a.update_date DESC"
)
public class ServiceOrder extends DataEntity<ServiceOrder> {
	
	private static final long serialVersionUID = 1L;
	private String serviceOrderId;		// 服务订单ID
	private String serviceOrderCode;		// 编号
	private String investorId;		// 国内资方
	private String yearCarSalePurchaseAgreementId;		// 年度汽车买卖协议
	private String customerId;		// 客户
	private String contractNumber;		// 汽车买卖合同号
	private String supplyChainServiceAgreementId;		// 供应链服务协议
	private String foreignBusinessmenId;		// 外商
	private String purchaseCommissionNumber;		// 采购委托书号
	private String supplierId;		// 供货外商
	private String foreignTradeContractNumber;		// 外贸合同号
	private String paymentMethod;		// 付款方式
	private Date date;		// 订单日期
	private String orderStatus;		// 状态
	private Date latestShipmentDate;		// 最晚装船日期
	private String fromPort;		// 装运港
	private String toPort;		// 目的港
	private String tradeTerm;		// 贸易术语
	private String currency;		// 币种
	private Double investorProfit;		// 资方利润（元）
	private String lotNumber;		// 批单号
	private String marginExpenseRatioId;		// 保证金、费用比例
	private String marginRatio;		// 保证金比例
	private String negotiatedRatioId;		// 押汇比例
	private String prePayRatio;		// 预收费比例
	private String tentativeExchangeRate;		// 暂定汇率
	private Long version;		// 版本号
	private String letterCreditCode;		// 信用证
	private List<ServiceOrderDetail> serviceOrderDetailList = ListUtils.newArrayList();		// 子表列表
	private Company company;
	private Customer customer;
	private Supplier supplier;
	private Supplier investor;
	private Supplier foreignBusinessmen;
	private Double totalAmount;
	private Double totalAgencyFee;
	private Double totalRiskMargin;
	private Double totalPrePay;
	private Double totalCost;
	private LetterCredit letterCredit;
	private ServiceOrderDetail serviceOrderDetail;
	private Boolean overseasWarehouseCode;
	private Boolean arrivalReminderCode;
	private String carId;
	private String frameNumber;
    private String createDateGte;
    private String createDateLte;
    private String carName;
    private String carLocation;
    private String logisticsStatus;
    private String lockFlag;
    private String warehouseName;
	private String bzjYusId;//保证金预收ID
	private String bzjYufId;//保证金预付ID
	private String ysfyId;//预收费用ID
	private String dlfYusId;//代理费预收ID
	private String dlfYufId;//代理费预付ID
	private String dlfYifId;//代理费应付ID
	private String dlfYisId;//代理费应收ID
	private String approveStatus;// 审批状态
	private List<RelatedRecord> relatedRecordList = ListUtils.newArrayList();		// 子表列表

	public List<RelatedRecord> getRelatedRecordList() {
		return relatedRecordList;
	}

	public void setRelatedRecordList(List<RelatedRecord> relatedRecordList) {
		this.relatedRecordList = relatedRecordList;
	}

	public String getApproveStatus() {
		return approveStatus;
	}

	public void setApproveStatus(String approveStatus) {
		this.approveStatus = approveStatus;
	}

	public String getBzjYusId() {
		return bzjYusId;
	}

	public void setBzjYusId(String bzjYusId) {
		this.bzjYusId = bzjYusId;
	}

	public String getBzjYufId() {
		return bzjYufId;
	}

	public String getWarehouseName() {
		return warehouseName;
	}

	public void setWarehouseName(String warehouseName) {
		this.warehouseName = warehouseName;
	}
	public void setBzjYufId(String bzjYufId) {
		this.bzjYufId = bzjYufId;
	}

	public String getYsfyId() {
		return ysfyId;
	}

	public void setYsfyId(String ysfyId) {
		this.ysfyId = ysfyId;
	}

	public String getDlfYusId() {
		return dlfYusId;
	}

	public void setDlfYusId(String dlfYusId) {
		this.dlfYusId = dlfYusId;
	}

	public String getDlfYufId() {
		return dlfYufId;
	}

	public void setDlfYufId(String dlfYufId) {
		this.dlfYufId = dlfYufId;
	}

	public String getDlfYifId() {
		return dlfYifId;
	}

	public void setDlfYifId(String dlfYifId) {
		this.dlfYifId = dlfYifId;
	}

	public String getDlfYisId() {
		return dlfYisId;
	}

	public void setDlfYisId(String dlfYisId) {
		this.dlfYisId = dlfYisId;
	}

	public LetterCredit getLetterCredit() {
		return letterCredit;
	}

	public void setLetterCredit(LetterCredit letterCredit) {
		this.letterCredit = letterCredit;
	}

	public Double getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(Double totalAmount) {
		this.totalAmount = totalAmount;
	}

	public Double getTotalAgencyFee() {
		return totalAgencyFee;
	}

	public void setTotalAgencyFee(Double totalAgencyFee) {
		this.totalAgencyFee = totalAgencyFee;
	}

	public Double getTotalRiskMargin() {
		return totalRiskMargin;
	}

	public void setTotalRiskMargin(Double totalRiskMargin) {
		this.totalRiskMargin = totalRiskMargin;
	}

	public Double getTotalPrePay() {
		return totalPrePay;
	}

	public void setTotalPrePay(Double totalPrePay) {
		this.totalPrePay = totalPrePay;
	}

	public Double getTotalCost() {
		return totalCost;
	}

	public void setTotalCost(Double totalCost) {
		this.totalCost = totalCost;
	}

	public Supplier getSupplier() {
		return supplier;
	}

	public void setSupplier(Supplier supplier) {
		this.supplier = supplier;
	}

	public Supplier getInvestor() {
		return investor;
	}

	public void setInvestor(Supplier investor) {
		this.investor = investor;
	}

	public Supplier getForeignBusinessmen() {
		return foreignBusinessmen;
	}

	public void setForeignBusinessmen(Supplier foreignBusinessmen) {
		this.foreignBusinessmen = foreignBusinessmen;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public Company getCompany() {
		return company;
	}

	public void setCompany(Company company) {
		this.company = company;
	}

	public ServiceOrder() {
		this(null);
	}

	public ServiceOrder(String id){
		super(id);
	}
	
	public String getServiceOrderId() {
		return serviceOrderId;
	}

	public void setServiceOrderId(String serviceOrderId) {
		this.serviceOrderId = serviceOrderId;
	}
	
	@Length(min=0, max=100, message="编号长度不能超过 100 个字符")
	public String getServiceOrderCode() {
		return serviceOrderCode;
	}

	public void setServiceOrderCode(String serviceOrderCode) {
		this.serviceOrderCode = serviceOrderCode;
	}
	
	@NotBlank(message="国内资方不能为空")
	@Length(min=0, max=64, message="国内资方长度不能超过 64 个字符")
	public String getInvestorId() {
		return investorId;
	}

	public void setInvestorId(String investorId) {
		this.investorId = investorId;
	}
	
	@NotBlank(message="年度汽车买卖协议不能为空")
	@Length(min=0, max=64, message="年度汽车买卖协议长度不能超过 64 个字符")
	public String getYearCarSalePurchaseAgreementId() {
		return yearCarSalePurchaseAgreementId;
	}

	public void setYearCarSalePurchaseAgreementId(String yearCarSalePurchaseAgreementId) {
		this.yearCarSalePurchaseAgreementId = yearCarSalePurchaseAgreementId;
	}
	
	@Length(min=0, max=64, message="客户长度不能超过 64 个字符")
	public String getCustomerId() {
		return customerId;
	}

	public void setCustomerId(String customerId) {
		this.customerId = customerId;
	}
	
	@Length(min=0, max=50, message="汽车买卖合同号长度不能超过 50 个字符")
	public String getContractNumber() {
		return contractNumber;
	}

	public void setContractNumber(String contractNumber) {
		this.contractNumber = contractNumber;
	}
	
	@NotBlank(message="供应链服务协议不能为空")
	@Length(min=0, max=64, message="供应链服务协议长度不能超过 64 个字符")
	public String getSupplyChainServiceAgreementId() {
		return supplyChainServiceAgreementId;
	}

	public void setSupplyChainServiceAgreementId(String supplyChainServiceAgreementId) {
		this.supplyChainServiceAgreementId = supplyChainServiceAgreementId;
	}
	
	@NotBlank(message="外商不能为空")
	@Length(min=0, max=64, message="外商长度不能超过 64 个字符")
	public String getForeignBusinessmenId() {
		return foreignBusinessmenId;
	}

	public void setForeignBusinessmenId(String foreignBusinessmenId) {
		this.foreignBusinessmenId = foreignBusinessmenId;
	}
	
	@Length(min=0, max=100, message="采购委托书号长度不能超过 100 个字符")
	public String getPurchaseCommissionNumber() {
		return purchaseCommissionNumber;
	}

	public void setPurchaseCommissionNumber(String purchaseCommissionNumber) {
		this.purchaseCommissionNumber = purchaseCommissionNumber;
	}
	
	@NotBlank(message="供货外商不能为空")
	@Length(min=0, max=64, message="供货外商长度不能超过 64 个字符")
	public String getSupplierId() {
		return supplierId;
	}

	public void setSupplierId(String supplierId) {
		this.supplierId = supplierId;
	}
	
	@NotBlank(message="外贸合同号不能为空")
	@Length(min=0, max=100, message="外贸合同号长度不能超过 100 个字符")
	public String getForeignTradeContractNumber() {
		return foreignTradeContractNumber;
	}

	public void setForeignTradeContractNumber(String foreignTradeContractNumber) {
		this.foreignTradeContractNumber = foreignTradeContractNumber;
	}
	
	@NotBlank(message="付款方式不能为空")
	@Length(min=0, max=2, message="付款方式长度不能超过 2 个字符")
	public String getPaymentMethod() {
		return paymentMethod;
	}

	public void setPaymentMethod(String paymentMethod) {
		this.paymentMethod = paymentMethod;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@NotNull(message="订单日期不能为空")
	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}
	
	@Length(min=0, max=1, message="状态长度不能超过 1 个字符")
	public String getOrderStatus() {
		return orderStatus;
	}

	public void setOrderStatus(String orderStatus) {
		this.orderStatus = orderStatus;
	}
	
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@NotNull(message="最晚装船日期不能为空")
	public Date getLatestShipmentDate() {
		return latestShipmentDate;
	}

	public void setLatestShipmentDate(Date latestShipmentDate) {
		this.latestShipmentDate = latestShipmentDate;
	}
	
	@NotBlank(message="装运港不能为空")
	@Length(min=0, max=2, message="装运港长度不能超过 2 个字符")
	public String getFromPort() {
		return fromPort;
	}

	public void setFromPort(String fromPort) {
		this.fromPort = fromPort;
	}
	
	@NotBlank(message="目的港不能为空")
	@Length(min=0, max=2, message="目的港长度不能超过 2 个字符")
	public String getToPort() {
		return toPort;
	}

	public void setToPort(String toPort) {
		this.toPort = toPort;
	}
	
	@NotBlank(message="贸易术语不能为空")
	@Length(min=0, max=2, message="贸易术语长度不能超过 2 个字符")
	public String getTradeTerm() {
		return tradeTerm;
	}

	public void setTradeTerm(String tradeTerm) {
		this.tradeTerm = tradeTerm;
	}
	
	@NotBlank(message="币种不能为空")
	@Length(min=0, max=2, message="币种长度不能超过 2 个字符")
	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}
	
	@NotNull(message="资方利润不能为空")
	public Double getInvestorProfit() {
		return investorProfit;
	}

	public void setInvestorProfit(Double investorProfit) {
		this.investorProfit = investorProfit;
	}
	
	@Length(min=0, max=100, message="批单号长度不能超过 100 个字符")
	public String getLotNumber() {
		return lotNumber;
	}

	public void setLotNumber(String lotNumber) {
		this.lotNumber = lotNumber;
	}
	
	@NotBlank(message="保证金、费用比例不能为空")
	@Length(min=0, max=64, message="保证金、费用比例长度不能超过 64 个字符")
	public String getMarginExpenseRatioId() {
		return marginExpenseRatioId;
	}

	public void setMarginExpenseRatioId(String marginExpenseRatioId) {
		this.marginExpenseRatioId = marginExpenseRatioId;
	}
	
	@Length(min=0, max=10, message="保证金比例长度不能超过 10 个字符")
	public String getMarginRatio() {
		return marginRatio;
	}

	public void setMarginRatio(String marginRatio) {
		this.marginRatio = marginRatio;
	}
	
	@Length(min=0, max=64, message="押汇比例长度不能超过 64 个字符")
	public String getNegotiatedRatioId() {
		return negotiatedRatioId;
	}

	public void setNegotiatedRatioId(String negotiatedRatioId) {
		this.negotiatedRatioId = negotiatedRatioId;
	}
	
	@Length(min=0, max=10, message="预收费比例长度不能超过 10 个字符")
	public String getPrePayRatio() {
		return prePayRatio;
	}

	public void setPrePayRatio(String prePayRatio) {
		this.prePayRatio = prePayRatio;
	}
	
	@NotBlank(message="暂定汇率不能为空")
	@Length(min=0, max=10, message="暂定汇率长度不能超过 10 个字符")
	public String getTentativeExchangeRate() {
		return tentativeExchangeRate;
	}

	public void setTentativeExchangeRate(String tentativeExchangeRate) {
		this.tentativeExchangeRate = tentativeExchangeRate;
	}
	
	public Long getVersion() {
		return version;
	}

	public void setVersion(Long version) {
		this.version = version;
	}
	
	@Length(min=0, max=64, message="信用证长度不能超过 64 个字符")
	public String getLetterCreditCode() {
		return letterCreditCode;
	}

	public void setLetterCreditCode(String letterCreditCode) {
		this.letterCreditCode = letterCreditCode;
	}
	
	public Date getDate_gte() {
		return sqlMap.getWhere().getValue("date", QueryType.GTE);
	}

	public void setDate_gte(Date date) {
		sqlMap.getWhere().and("date", QueryType.GTE, date);
	}
	
	public Date getDate_lte() {
		return sqlMap.getWhere().getValue("date", QueryType.LTE);
	}

	public void setDate_lte(Date date) {
		sqlMap.getWhere().and("date", QueryType.LTE, date);
	}
	
	public Date getLatestShipmentDate_gte() {
		return sqlMap.getWhere().getValue("latest_shipment_date", QueryType.GTE);
	}

	public void setLatestShipmentDate_gte(Date latestShipmentDate) {
		sqlMap.getWhere().and("latest_shipment_date", QueryType.GTE, latestShipmentDate);
	}
	
	public Date getLatestShipmentDate_lte() {
		return sqlMap.getWhere().getValue("latest_shipment_date", QueryType.LTE);
	}

	public void setLatestShipmentDate_lte(Date latestShipmentDate) {
		sqlMap.getWhere().and("latest_shipment_date", QueryType.LTE, latestShipmentDate);
	}
	
	public Date getCreateDate_gte() {
		return sqlMap.getWhere().getValue("create_date", QueryType.GTE);
	}

	public void setCreateDate_gte(Date createDate) {
		sqlMap.getWhere().and("create_date", QueryType.GTE, createDate);
	}
	
	public Date getCreateDate_lte() {
		return sqlMap.getWhere().getValue("create_date", QueryType.LTE);
	}

	public void setCreateDate_lte(Date createDate) {
		sqlMap.getWhere().and("create_date", QueryType.LTE, createDate);
	}
	
	public List<ServiceOrderDetail> getServiceOrderDetailList() {
		return serviceOrderDetailList;
	}

	public void setServiceOrderDetailList(List<ServiceOrderDetail> serviceOrderDetailList) {
		this.serviceOrderDetailList = serviceOrderDetailList;
	}

    public ServiceOrderDetail getServiceOrderDetail() {
        return serviceOrderDetail;
    }

    public void setServiceOrderDetail(ServiceOrderDetail serviceOrderDetail) {
        this.serviceOrderDetail = serviceOrderDetail;
    }

    public String getCarId() {
        return carId;
    }

    public void setCarId(String carId) {
        this.carId = carId;
    }

    public String getFrameNumber() {
        return frameNumber;
    }

    public void setFrameNumber(String frameNumber) {
        this.frameNumber = frameNumber;
    }

    public String getCarName() {
        return carName;
    }

    public void setCarName(String carName) {
        this.carName = carName;
    }

    public String getCreateDateLte() {
        return createDateLte;
    }

    public void setCreateDateLte(String createDateLte) {
        this.createDateLte = createDateLte;
    }

    public String getCreateDateGte() {
        return createDateGte;
    }

    public void setCreateDateGte(String createDateGte) {
        this.createDateGte = createDateGte;
    }

    public String getCarLocation() {
        return carLocation;
    }

    public void setCarLocation(String carLocation) {
        this.carLocation = carLocation;
    }

    public String getLogisticsStatus() {
        return logisticsStatus;
    }

    public void setLogisticsStatus(String logisticsStatus) {
        this.logisticsStatus = logisticsStatus;
    }

    public String getLockFlag() {
        return lockFlag;
    }

    public void setLockFlag(String lockFlag) {
        this.lockFlag = lockFlag;
    }

    public Boolean getOverseasWarehouseCode() {
        return overseasWarehouseCode;
    }

    public void setOverseasWarehouseCode(Boolean overseasWarehouseCode) {
        this.overseasWarehouseCode = overseasWarehouseCode;
    }

    public Boolean getArrivalReminderCode() {
        return arrivalReminderCode;
    }

    public void setArrivalReminderCode(Boolean arrivalReminderCode) {
        this.arrivalReminderCode = arrivalReminderCode;
    }
}